package com.situ.day3;

import java.util.Scanner;

public class StudentMananger {
	public static void main(String[] args, Object newParam, Object newParam2, Object newParam3) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的人数： ");
		int count = scanner.nextInt();					//输入的学生的人数
		Students[] student = new Students[count];		//人数为数组的长度
		for (int i = 0; i < student.length; i++) {
			System.out.println("请输入学生的id: ");
			int id = scanner.nextInt();
			System.out.println("请输入学生的姓名： ");
			String name = scanner.next();
			System.out.println("请输入学生的年龄： ");
			int age = scanner.nextInt();
			System.out.println("请输入学生的班级： ");
			String className = scanner.next();		
			Students students = new Students(id,name,age,className); //把输入的数据赋值给students
			student[i] = students;									//students赋值给数组
		}
		
		System.out.println("学生成绩列表： ");							//打印所有的学生列表
		for (int i = 0; i < student.length; i++) {
			System.out.println(student[i]);
		}
		
		while (true) {											//死循环
			System.out.println("按id查询按1： ");
			System.out.println("按姓名查询按2： ");
			System.out.println("按年龄查询按3： ");
			System.out.println("按班级查询按4： ");
			System.out.println("退出按0： ");
			int type = scanner.nextInt();						//目的是输入0，退出循环
			if (type == 0) {
				System.out.println("退出程序");
				return;											//退出全部循环
			}
			switch (type) {										//输入的要查询的数字
			case 1:
				System.out.println("请输入要查询学生的id： ");
				int id1 = scanner.nextInt();
				boolean falg = false;                      //先假定是假
				for (int i = 0; i < student.length; i++) {
					Students students = student[i];			//把数组内的数遍历
					int id = students.getId();				//遍历数组把id取出来
					if (id1 == id) {						//把取出的id与输入的id比较
						System.out.println(students);		//比较完相同的话就进入循环，打印学生的数据
						falg = true; 					//真，不进下面的循环
					}
				}
				if (falg == false) {					//为假进入循环
					System.out.println("没有该id的学生： ");
				}
//				System.out.println("id");
				break;
				
				
			case 2:
//				System.out.println("姓名");
				System.out.println("请输入要查询学生的姓名： ");
				String  name1 = scanner.next();
				boolean flag = false;
				for (int i = 0; i < student.length; i++) {
					Students students = student[i];
					String name = students.getName();
					if (name1.equals(name)) {
						System.out.println(students);
						flag = true;
					}
				}
				if (flag == false) {
					System.out.println("没有该学生");
				}
				break;
				
			case 3:
				System.out.println("请输入要查询学生的年龄： ");
				int age1 = scanner.nextInt();
				boolean fal = false;
				for (int i = 0; i < student.length; i++) {
					Students students = student[i];
					int age = students.getAge();
					if (age1 == age) {
						System.out.println(students);
						fal = true;
					}
				}
				if (fal = false) {
					System.out.println("找不到该年龄的学生： ");
				}
//				System.out.println("年龄");
				break;
				
				
			case 4:
//				System.out.println("班级");
				System.out.println("请输入要查询学生的班级： ");
				String className1 = scanner.next();
				boolean fa = false;
				for (int i = 0; i < student.length; i++) {
					Students students = student[i];
					String className = students.getClassName();
					if (className1.equals(className) ) {
						System.out.println(students);
						fa = true;
					}
				}
				if (fa == false) {
					System.out.println("找不到该班级的学生");
				}
				break;

			default:
				System.out.println("错误");
				break;
			}
		}
	}
}